package com.twu.biblioteca;

import java.util.Scanner;

public class BibliotecaApp {

    private static final String INVALID_OPTION_NOTICE = "Select a valid option!!";
    private Controller controller;

    public static void main(String[] args) {
        BibliotecaApp bibliotecaApp = new BibliotecaApp();
        bibliotecaApp.process();
    }

    BibliotecaApp () {
        controller = new Controller();
    }

    private String printStartInfo() {
        return controller.printStartInfo();
    }

    public void process() {
        int choice = 0;
        while(true) {
            System.out.println(printStartInfo());
            choice = inputOption();
            System.out.println(selectOption(choice));
        }
    }

    public int inputOption() {
        try {
            Scanner scanner = new Scanner(System.in);
            int optionNum =  scanner.nextInt();
            return optionNum;
        } catch(java.util.InputMismatchException e) {
            return -1;
        }
    }

    public String selectOption(int choice) {
        if(controller.contains(choice))
            return controller.execute(choice);
        else
            return INVALID_OPTION_NOTICE;
    }
}
